<template>
	<view>
		<!-- 头部搜索框 -->
		<search :placeholder="$t('homepage.AccessoryManagement.partInstorageCode')" />
		<!-- 搜索无记录 -->
		<zy-empty v-if="!this.data"></zy-empty>
		<zy-cell :cellList="cellList" :title="$t('homepage.AccessoryManagement.function')" v-else></zy-cell>
	</view>
</template>

<script>
	import {
		getMapyByField,
	} from "@/api/homepage.js"
	export default {
		data() {
			return {
				data: false,
				cellList: [{
					iconfont: 'iconfont icon-cangweiguanli',
					text: this.$t('homepage.AccessoryManagement.warehousePositionInstorage'),
					url: "./positionList",
					sufIcon: "iconfont icon-xiangyou",
				}, {
					iconfont: 'iconfont icon-chuwei',
					text: this.$t('homepage.AccessoryManagement.storageInstorage'),
					url: "./storagePositionList",
					sufIcon: "iconfont icon-xiangyou",
				}]
			}
		},
		onLoad() {
			//PDA扫描
			var _this = this
			uni.$on('scancodedate', function(data) {
				_this.searchList(data.code)
			})
		},
		onUnload() {
			// 移除监听事件      
			uni.$off('scancodedate')
		},
		methods: {
			searchList(e) {
				getMapyByField({
					fieldValue: e,
					fieldName: 'billNo'
				}).then((res) => {
					if (res.code == 0) {
						this.data = true
						this.$store.commit('accessoryId', res.data.id)
					} else {
						uni.showToast({
							title: res.message,
							icon: "none",
							duration: 3000
						})
					}
				}).catch((res) => {
					uni.showToast({
						title: res.message,
						icon: "none",
						duration: 3000
					})
				});
			},
		}
	}
</script>

<style lang="scss" scoped>
	.list {
		background-color: #fff;
		border-radius: 4px;
		width: calc(100%-40px);
		margin: 10px;
		padding: 20px 0;
	}

	.img {
		width: 50px;
		height: 50px;

	}

	.text {
		font-size: 14px;
		color: #909399;
		padding: 10rpx 0 10rpx 0rpx;
		box-sizing: border-box;
	}
</style>